package com.yanchi.prototype.shallow;

import java.util.Date;

public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {

        // 创建一个人类张三
        Date date = new Date();
        System.out.println(date);
        Person person = new Person("张三" , date);

        // 克隆人类张三生成新人类
        Person personCopy = person.clone();

        // hashCode不同，确实是两个对象
        System.out.println("本体：" + person);
        System.out.println("本体：" + person.hashCode());
        System.out.println("克隆体：" + personCopy);
        System.out.println("克隆体：" + personCopy.hashCode());


        System.out.println("==================================================");
        date.setTime(2312323213212L);
        // 浅拷贝拷贝对象的属性引用，导致克隆体的数据也发生变化
        System.out.println("本体：" + person);
        System.out.println("克隆体：" + personCopy);

    }
}
